package com.itheima.xx.e_request_01;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Description:
 *
 * @author codermao
 * @date 2023/11/1 11:47
 */
@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");

        System.out.println("username -> " + username);
        String pwd = req.getParameter("pwd");
        System.out.println("pwd -> " + pwd);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //方式三：
        req.setCharacterEncoding("utf-8");

        String username = req.getParameter("username");
        //方式一：
        /*String encodeUserName = URLEncoder.encode(username, "iso-8859-1");
        username = URLDecoder.decode(encodeUserName, "utf-8");*/

        //方式二：
        /*byte[] bytes = username.getBytes("iso-8859-1");
        username = new String(bytes,"utf-8");*/

        System.out.println("username -> " + username);
        String pwd = req.getParameter("pwd");
        System.out.println("pwd -> " + pwd);
    }
}
